package com.earnings.okhttputils.utils.OkHttp.utils;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Administrator on 2017/3/28 0028.
 */

public class Md5Utils {

    /**
     * 招财汇报专用MD5
     *
     * @param tag
     * @param password
     * @return
     */
    public static String getMd5Value(String tag, String password) {
        password = tag + password;
        try {
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(password.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();// 加密
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 百世商城MD5
     *
     * @param password
     * @return
     */
    public static String getMd5Value(String password) {
        return password;
       /* password = "BSSC" + password;
        try {
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(password.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();// 加密
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";*/
    }

    /**
     * 百世商城MD5
     *
     * @param password
     * @param unique_id
     * @param username
     * @param time
     * @return
     */
    public static String getMd5User(String password, String unique_id, String username, String time) {
        String md5 = password + unique_id + username + time + "bssc1001";
        try {
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(md5.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();// 加密
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
